
cmake_minimum_required(VERSION 3.15)

project(render_demo)

set(CMAKE_CXX_STANDARD 20)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build)
file(GLOB_RECURSE shaders "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/*" "${CMAKE_CURRENT_SOURCE_DIR}/src/snippets/shaders/*")
file(COPY ${shaders}  DESTINATION ${EXECUTABLE_OUTPUT_PATH})
file(GLOB resources  "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/*")
file(COPY ${resources}  DESTINATION ${EXECUTABLE_OUTPUT_PATH})


set(LINK_WHAT_YOU_USE true)

if(iwyu_path)
set(CMKAE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endif()

if(tidy_path)
set(CMKAE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CXX_CLANG_TIDY ${tidy_path})
endif()

file(GLOB CORE "${CMAKE_CURRENT_SOURCE_DIR}/src/source/core/*.cc")
file(GLOB GL "${CMAKE_CURRENT_SOURCE_DIR}/src/source/graphics/*.cc")

add_library(umikaze STATIC ${CORE} ${GL})

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
  include_directories("E:/code/glm" )
  target_link_directories(umikaze PUBLIC "E:/code/glew-2.1.0/lib/Release/x64")
  target_link_directories(umikaze PUBLIC "E:/code/glew-2.1.0/bin/Release/x64")
  target_link_directories(umikaze PUBLIC "E:/code/glfw-3.3.5.bin.WIN64/lib-mingw-w64")
  include_directories(${SNIPPET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/include")
  file(COPY "E:/code/glew-2.1.0/bin/Release/x64/glew32.dll" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
  target_link_libraries(umikaze "glew32" "opengl32" "glew32s" "glfw3")

  target_include_directories(umikaze PRIVATE "E:/code/glew-2.1.0/include")
  target_include_directories(umikaze PRIVATE "E:/code/stb" )
  target_include_directories(umikaze PRIVATE "E:/code/glfw-3.3.5.bin.WIN64/include" )
  target_include_directories(umikaze PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/source" )

  include_directories("E:/code/glew-2.1.0/include")
  include_directories("E:/code/stb" )
  include_directories("E:/code/glfw-3.3.5.bin.WIN64/include" )
  include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/source" )

else()
  find_package(glm REQUIRED)

  find_package(GLFW3 REQUIRED)

  find_package(GLEW REQUIRED)

  find_package(assimp REQUIRED)

  find_program(iwyu_path NAMES include-what-you-use iwyu)
  if(NOT iwyu_path)
    message(WARNING "Could not find the program include-what-you-use")
  endif()


  find_program(tidy_path NAMES clang-tidy)
  if(NOT tidy_path)
      message(WARNING "Could not find the program clang-tidy")
  endif()

    #最好是自己重写一下glm等库的cmake-config
  target_include_directories(umikaze  PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/include"  PRIVATE "/usr/local/include" "${CMAKE_CURRENT_SOURCE_DIR}/src/source")
  
  link_directories("/usr/local/lib")
  target_link_libraries(umikaze PRIVATE glm::glm GLEW::glew glfw assimp)

endif()

file(GLOB SNIPPET "${CMAKE_CURRENT_SOURCE_DIR}/src/snippets/*.cc")

foreach(FULLPATH ${SNIPPET})

    string(REPLACE "/" ";" TEMP_STRING ${FULLPATH})

    list(GET TEMP_STRING -1 SNIPPET_NAME_WITH_DOT_CC)

    string(REPLACE "." ";" TEMP_STRING ${SNIPPET_NAME_WITH_DOT_CC})

    list(GET TEMP_STRING 0 SNIPPET_NAME)

    message(${SNIPPET_NAME})

    add_executable(${SNIPPET_NAME} ${FULLPATH})

    target_link_libraries(${SNIPPET_NAME} PUBLIC umikaze)

    target_include_directories(${SNIPPET_NAME} PRIVATE "/usr/local/include" "${CMAKE_CURRENT_SOURCE_DIR}/src/snippets")
    
    

endforeach()


# register_target(umikaze)

# set(targets "" CACHE INTERNAL "container of all targets")

# function(register_target target)
#     set(targets "${targets};${target}" CACHE INTERNAL "container of all targets")
# endfunction(register_target target)

# add_subdirectory(ssr)
# add_subdirectory(csm)
# add_subdirectory(checkboardtest)
# add_subdirectory(umikaze)

 
# foreach(target ${targets})
 
#     set_target_properties(${target}
#         PROPERTIES
#         ARCHIVE_OUTPUT_DIRECTORY "./${target}/build"
#         LIBRARY_OUTPUT_DIRECTORY "./${target}/build"
#         RUNTIME_OUTPUT_DIRECTORY "./${target}/build"
#     )

# endforeach()




